using System;
using System.Runtime.Serialization;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.BO;
using Habanero.Smooth;

namespace FireStarterModeller.Test.BO.Fakes
{

    public class FakeDMClass : DMClass
    {
        private BusinessObjectCollection<DMRelationship> _relationships;

        public FakeDMClass()
            : base(ConstructForFakes.True)
        {
        }
        public void SetRelationshipsDM(BusinessObjectCollection<DMRelationship> relationships)
        {
            _relationships = relationships;
        }

        public override BusinessObjectCollection<DMRelationship> RelationshipsDM
        {
            get
            {
                return _relationships ?? base.RelationshipsDM;
            }
        }

        public override string AssemblyName { get; set; }

        protected override IClassDef ConstructClassDef()
        {
            AllClassesAutoMapper.ClassDefCol = Habanero.BO.ClassDefinition.ClassDef.ClassDefs;
            return this.GetType().MapClass();
        }
    }
    public class FakeDMSolution : DMSolution
    {
        public FakeDMSolution()
            : base(ConstructForFakes.True)
        {
        }
        protected override IClassDef ConstructClassDef()
        {
            AllClassesAutoMapper.ClassDefCol = Habanero.BO.ClassDefinition.ClassDef.ClassDefs;
            return this.GetType().MapClass();
        }
    }
    public class FakeDMRelationshipProperty : DMRelationshipProperty
    {
        private DMClass _ownerClass;

        public FakeDMRelationshipProperty()
            : this((IClassDef)null)
        {
        }
        // ReSharper disable DoNotCallOverridableMethodsInConstructor
        public FakeDMRelationshipProperty(IDMRelationshipProperty reverseRelationshipProperty)
            : this((IClassDef)null)
        {
            ReverseRelationshipProperty = reverseRelationshipProperty;
        }

        protected override IClassDef ConstructClassDef()
        {
            AllClassesAutoMapper.ClassDefCol = Habanero.BO.ClassDefinition.ClassDef.ClassDefs;
            return this.GetType().MapClass();
        }

        protected internal FakeDMRelationshipProperty(IClassDef def)
            : this(ConstructForFakes.True)
        {
        }

        protected FakeDMRelationshipProperty(ConstructForFakes constructForFakes)
            : base(ConstructForFakes.True)
        {
       /*     ClassAutoMapper mapper = new ClassAutoMapper(typeof(FakeDMRelationshipProperty));
            var classDef = mapper.MapPropertiesOnly();*/
            _relationshipCol = new RelationshipCol(this);
            //InitialiseForFakes(classDef);
            // ReSharper restore DoNotCallOverridableMethodsInConstructor
        }

        protected FakeDMRelationshipProperty(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        public override Guid? RelationshipPropertyID { get; set; }

        public override Guid? RelationshipID { get; set; }

        public override Guid? PropertyID { get; set; }

        public override Boolean? Generated { get; set; }

        public override string RelatedPropertyName { get; set; }

        public override string OwnerPropertyName { get; set; }

        public override IDMProperty OwnerProperty { get; set; }

        public override IDMProperty RelatedProperty { get; set; }

        public override DMClass OwnerClass
        {
            get { return _ownerClass; }
        }


        public void SetOwnerClass(DMClass ownerClass)
        {
            _ownerClass = ownerClass;
        }

        public override IDMRelationshipProperty ReverseRelationshipProperty { get; set; }

        public override IDMProperty Property { get; set; }

        public override IDMRelationship Relationship { get; set; }

    }

    public class FakeDMRelationship : DMRelationship
    {
        private string _ownerClassName;
        private BusinessObjectCollection<DMRelationshipProperty> _relProps;
        private bool? _owninigBoHasFK;
        private bool? _relatedBOHasForeignKey;

        public FakeDMRelationship()
            : this((IClassDef)null)
        {
        }

        // ReSharper disable DoNotCallOverridableMethodsInConstructor
        public FakeDMRelationship(IDMRelationship reverseRelationship)
            : this((IClassDef)null)
        {
        }

        // ReSharper restore DoNotCallOverridableMethodsInConstructor

        protected internal FakeDMRelationship(IClassDef def)
            : base((IClassDef)null)
        {
        }

        public FakeDMRelationship(ConstructForFakes constructForFakes)
            : base(ConstructForFakes.True)
        {
        }

        protected FakeDMRelationship(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        protected override IClassDef ConstructClassDef()
        {
            AllClassesAutoMapper.ClassDefCol = Habanero.BO.ClassDefinition.ClassDef.ClassDefs;
            return this.GetType().MapClass();
        }


        [AutoMapIgnore]
        public override IDMRelationship ReverseRelationship { get; set; }
        [AutoMapIgnore]
        public override RelationshipType? RelationshipType { get; set; }
        [AutoMapIgnore]
        public override string OwnerClassName
        {
            get { return _ownerClassName; }
        }

        public void SetOwnerClassName(string name)
        {
            _ownerClassName = name;
        }
        [AutoMapIgnore]
        public override string RelationshipName { get; set; }
        [AutoMapIgnore]
        public override IDMClass ClassDM { get; set; }
        //        public override bool IsMultiple { get; set; }
        //        public override bool IsCompositionOrAggregation { get; set; }
        [AutoMapIgnore]
        public override Cardinality? Cardinality { get; set; }
        [AutoMapIgnore]
        public override IDMClass OwnerClass { get; set; }
        [AutoMapIgnore]
        public override IDMClass RelatedClass { get; set; }
        [AutoMapIgnore]
        public override DeleteParentAction? DeleteAction { get; set; }
        [AutoMapIgnore]
        public override BusinessObjectCollection<DMRelationshipProperty> RelationshipProperties
        {
            get { return _relProps; }
        }

        public override bool RelatedBOHasForeignKey
        {
            get { return _relatedBOHasForeignKey ?? base.RelatedBOHasForeignKey; }
        }

        public void SetRelatedBOHasForeignKey(bool relatedBOHasForeignKey)
        {
            _relatedBOHasForeignKey = relatedBOHasForeignKey;
        }
        public void SetRelationshipProperties(BusinessObjectCollection<DMRelationshipProperty> relProps)
        {
            _relProps = relProps;
        }
        [AutoMapIgnore]
        public override string RelatedClassName { get; set; }
        [AutoMapIgnore]
        public override string ReverseRelationshipName { get; set; }
        [AutoMapIgnore]
        public override string RelatedAssemblyName { get; set; }

        public void SetOwningBOHasForeignKey(bool owningBoHasFK)
        {
            _owninigBoHasFK = owningBoHasFK;
        }
        [AutoMapIgnore]
        public override bool OwningBOHasForeignKey
        {
            get { return _owninigBoHasFK ?? base.OwningBOHasForeignKey; }
            set { throw new NotImplementedException(); }
        }


    }

    public class UIViewFake : UIView
    {
        protected override IClassDef ConstructClassDef()
        {
            AllClassesAutoMapper.ClassDefCol = Habanero.BO.ClassDefinition.ClassDef.ClassDefs;
            return this.GetType().MapClass();
        }
        [AutoMapIgnore]
        public override DMClass Class { get; set; }
    }
    // ReSharper restore UnusedMember.Global
}


